package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* CommunityView
* */
class CommunityView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mPaint by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeCap = Paint.Cap.ROUND
            strokeJoin = Paint.Join.ROUND
            color = context.resources.getColor(R.color.color_2A66CA)
        }
    }

    private val mPath by lazy {
        Path()
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            translate(cx, cy)
            mPath.apply {
                moveTo(-cx, cy)
                lineTo(-cx * 3 / 7, cy)
                lineTo(-cx * 3 / 7, 0F)
                arcTo(
                    -cx * 3 / 7,
                    -cy * 3 / 7,
                    cx * 3 / 7,
                    cy * 3 / 7,
                    180F,
                    180F,
                    false
                )
                lineTo(cx * 3 / 7, cy)
                lineTo(cx, cy)
                lineTo(cx, -cy * 5 / 7)
                lineTo(0F, -cy)
                lineTo(-cx, -cy * 5 / 7)
            }
            drawPath(mPath, mPaint)
        }
    }
}